﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Theme_index_News : PowerCreator.LMS.Web.Base.WebBasePage
{
    PowerCreator.LMS.Web.CMS.NewType opNewsType = new PowerCreator.LMS.Web.CMS.NewType();
    PowerCreator.LMS.Web.CMS.New opNews = new PowerCreator.LMS.Web.CMS.New();
    protected PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = config.GetLanagerValueByKey("theme_menu_News", PowerCreator.LMS.Language.LanagetItemType.Page);
        string type = "";
        if (!IsPostBack)
        {
            if (Request.QueryString["type"] != null)
            {
                type = Request.QueryString["type"];
            }
            if (type == "jyzx")
                type = "教育资讯";
            else if (type == "jyzt")
                type = "教育专题";
            else if (type == "szyw")
                type = "时政要闻";
            //BinderNewNews();
            BinderNewsType(type);
        }
    }

    protected override void InitPage()
    {
        base.InitPage();
    }
    //private void BinderNewNews()
    //{
    //    string search = " NewState = 1";
    //    string orderBy = " NewPublishTime desc ";
    //    DataTable dt = opNews.Query(search, orderBy, PowerCreator.LMS.Web.Config.WebConfig.PageSize, 1);
    //    rpt_NewNews.DataSource = dt;
    //    rpt_NewNews.DataBind();
    //}

    private void BinderNewsType(string strtype)
    {
        string search = "";
        if (strtype.Length > 0)
            search = "NewTypeName='"+strtype+"'";
        string orderby = "NewIsTop desc, NewPublishTime desc ";
        DataTable dt = opNewsType.Query(search);
        rpt_NewsType.DataSource = dt;
        rpt_NewsType.DataBind();
        for (int i = 0; i < rpt_NewsType.Items.Count; i++)
        {
            Label lbl_NewTypeID = (Label)rpt_NewsType.Items[i].FindControl("lbl_NewTypeID");
            Repeater rpt_News = (Repeater)rpt_NewsType.Items[i].FindControl("rpt_News");
            if (rpt_News != null)
            {
                search = string.Format("FKNewNewTypeID = {0} and NewState = 1", lbl_NewTypeID.Text);
                DataTable dt1 = opNews.Query(search, orderby, 5, 1);
                for (int j = 0; j < dt1.Rows.Count; j++)
                {
                    if (dt1.Rows[j]["NewUrl"] == null)
                        dt1.Rows[j]["NewUrl"] = "OpenNews.aspx?NewsID=" + dt1.Rows[j]["NewID"].ToString();
                    else if (dt1.Rows[j]["NewUrl"].ToString().Length == 0)
                        dt1.Rows[j]["NewUrl"] = "OpenNews.aspx?NewsID=" + dt1.Rows[j]["NewID"].ToString();
                }

                rpt_News.DataSource = dt1;
                rpt_News.DataBind();
            }
        }
    }
}
